package com.ruoyi.web.controller.system;


import freemarker.template.Configuration;
import freemarker.template.Template;

import java.io.File;
import java.io.FileWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

public class index {


    public static void main(String[] args) throws Exception {

//        Configuration cfg = new Configuration(Configuration.VERSION_2_3_31);
//        cfg.setDirectoryForTemplateLoading(new File("D:\\project\\东方巨龙\\developCode\\dfjloffice\\RuoYi-App\\ruoyi-admin\\src\\main\\resources\\index.ftl")); // 模板目录
//        cfg.setDefaultEncoding("UTF-8");
//
//        Map<String, Object> data = new HashMap<>();
//        data.put("user", "World");
//        Template template = cfg.getTemplate("hello.ftl");
//        StringWriter writer = new StringWriter();
//        template.process(data, writer);
//        System.out.println(writer.toString()); // 输出：Hello World!

        //1.创建配置类
        Configuration configuration = new Configuration(Configuration.VERSION_2_3_31);
        //
        configuration.setDirectoryForTemplateLoading(new File("D:\\project\\东方巨龙\\developCode\\dfjloffice\\RuoYi-App\\ruoyi-admin\\src\\main\\resources"));
        //3.设置字符集
        configuration.setDefaultEncoding("utf-8");
        //4.加载模板
        Template template = configuration.getTemplate("index.ftl");

        //5.创建数据模型
        Map map=new HashMap();
        map.put("name", "张三");
        map.put("title", "欢迎来使用Freemarker！");
        map.put("content", "欢迎来使用Freemarker！");
         //6.创建Writer对象
        Writer out =new FileWriter(new File("D:\\project\\东方巨龙\\wwwroot\\hello.html"));
        //7.输出
        template.process(map, out);
        //8.关闭Writer对象
        out.close();



    }

}
